package com.xxl.controll;

import com.xxl.util.EmailUtil;
import jakarta.annotation.Resource;
import jakarta.mail.MessagingException;
import jakarta.validation.constraints.Email;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Random;

/**
 * 邮件控制类
 * @author xxl
 * @date 2023/3/19
 */
@Controller
@Validated
public class EmailController {
    public static String verificationCode = "";
    @Resource
    EmailUtil util;


    @GetMapping("/email")
    public String register(@Email @RequestParam("email") String email) throws MessagingException {
        util.complexEmail(email);
        return "/verify.html";
    }


    @GetMapping("home")
    public String valid(@RequestParam("validCode")String validCode,Model model) {
        if (EmailController.verificationCode.equals(validCode)) {
            return "/home.html";
        }
        model.addAttribute("msg","验证码不对");
        return "/index";
    }


}
